#include<iostream>
#include<memory>
#include"Log.hpp"
#include"UdpServer.hpp"
#include"InetAddr.hpp"
#include"ThreadPool.hpp"
#include"Route.hpp"
using namespace ThreadPoolModule;
// ./udpserver server_port
typedef std::function<void()> task_t;

int main(int argc, char** argv)
{
    if(argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << "port" << std::endl;
        exit(1);
    }

    uint16_t port = std::stoi(argv[1]);
    Enable_Console_Log_Strategy();

    //1、路由服务
    Route route;

    //2、线程池
    auto thread_pool = ThreadPool<task_t>::GetInstance();

    //3、网络服务器对象，提供通信功能
    std::unique_ptr<UdpServer> usvr = std::make_unique<UdpServer>(port, [&route, &thread_pool](int sockfd, const std::string& message, InetAddr& peer){
        task_t task = std::bind(&Route::MessageRoute, &route, sockfd, message, peer);
        thread_pool->Enqueue(task);
    });
    usvr->Init();
    usvr->Start();

    return 0;
}